package com.clz.mycustomview

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.graphics.drawable.AnimationUtilsCompat
import android.view.View
import android.view.animation.*
import kotlinx.android.synthetic.main.activity_view_animation.*

class ViewAnimationActivity : AppCompatActivity(), View.OnClickListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_view_animation)
        btn.setOnClickListener(this)

    }

    override fun onClick(v: View?) {
        when(v?.id){
            R.id.btn -> {
//                val loadAnimation = AnimationUtils.loadAnimation(this, R.anim.animation_set)
//                var animation = RotateAnimation(0f,360f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f)
//                animation.duration = 3000;
//                tv.startAnimation(animation)
                // 镜头由远及近效果
//                val scaleAnimation = ScaleAnimation(1.0f,1.2f,1.0f,1.2f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f)
//                scaleAnimation.fillAfter = true
//                scaleAnimation.duration = 6000
//                scaleAnimation.interpolator = BounceInterpolator()
//                iv_scenery.startAnimation(scaleAnimation)

                // 加载动画效果
                val rotateAnimation = RotateAnimation(0f,360f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f)
                rotateAnimation.repeatCount = Animation.INFINITE
                rotateAnimation.duration = 2000
                rotateAnimation.interpolator = LinearInterpolator()
                iv_loading.startAnimation(rotateAnimation)
            }
        }
    }
}